package main

import (
	"fmt"

	"github.com/desyang-hub/zinx_demo/zface"
	"github.com/desyang-hub/zinx_demo/znet"
)

// user
type CustomerRouter struct {
	znet.BaseRouter
}

func (r *CustomerRouter) PreHandle(request zface.IRequest) {
	fmt.Println("PreHandle...")
}
func (r *CustomerRouter) Handle(request zface.IRequest) {
	fmt.Println("Handle...")
	fmt.Println("[msg info] ", string(request.GetMessage().GetMsgData()))
	request.GetConnection().Send(request.GetMessage().GetMsgID(), string(request.GetMessage().GetMsgData()))
}
func (r *CustomerRouter) PostHandle(request zface.IRequest) {
	fmt.Println("PostHandle...")
}

type PingRouter struct {
	znet.BaseRouter
}

// Handle 是 CustomerRouter 结构体的方法，用于处理请求
func (r *PingRouter) Handle(request zface.IRequest) {
	// 打印处理信息
	fmt.Println("Handle...")
	request.GetConnection().Send(200, "ping "+string(request.GetMessage().GetMsgData()))
}

func main() {
	// 模板方法(设计模式)
	server := znet.NewServer()

	server.AddRouter(0, &CustomerRouter{})

	server.AddRouter(1, &PingRouter{})

	server.Serve()
}
